package com.hutou.chuangke.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.hutou.chuangke.Bean.CollBean;
import com.hutou.chuangke.Bean.MvlistBean;
import com.hutou.chuangke.Bean.SoundBean;
import com.hutou.chuangke.Bean.UserSoundBean;
import com.hutou.chuangke.MainApplication;
import com.hutou.chuangke.R;
import com.hutou.chuangke.adapter.ImageGridviewAdapter;
import com.hutou.chuangke.androidbug.AndroidBug5497Workaround;
import com.hutou.chuangke.dialog.NetDailog;
import com.hutou.chuangke.handler.HandlerUtil;
import com.hutou.chuangke.net.HttpUtil;
import com.hutou.chuangke.net.RequestThreadPool;
import com.hutou.chuangke.net.http.HttpUrl;
import com.hutou.chuangke.net.http.User;
import com.hutou.chuangke.service.MusicPlayer;
import com.hutou.chuangke.uitl.CommonUtils;
import com.hutou.chuangke.uitl.Comparator.UrlUtils;
import com.hutou.chuangke.uitl.Utils;
import com.hutou.chuangke.widget.CircleImageView;
import com.hutou.chuangke.widget.DividerItemDecoration;
import com.hutou.chuangke.widget.MyGridview;
import com.hutou.chuangke.widget.MyVideoView;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/4/17.
 */

public class VideoViewActivity extends BaseActivity implements View.OnClickListener {
    private MyVideoView videoView;
    private Button all_creen;
    private RelativeLayout video_layout;
    Toolbar toolbar;
    private boolean fullscreen = false;//全屏/窗口播放切换标志
    private Context mContext;
    private int actiobarhei;
    private String mvurl;
    private String mvid;
    private RecyclerView video_recyclerviewew;
    private Button send_bt;
    private EditText colle_et;
    private MvlistBean mvlistBean;
    private UserSoundBean userSoundBean;

    private TextView title_tv,singer_tv,collection_number_tv;
    private LinearLayout collection_layout,down_layout,share_layout;
    private CheckBox mv_collection_checkbox;

    private VideoCommentAdapter adapter;
    private LinearLayoutManager manger;
    private ArrayList<CollBean> mData = new ArrayList<>();
    private String strcoll;//评论内容
    LoadCollListInfo loadCollListInfo;
    RequestSend requestSend;
    RequestReply requestReply;
    NetDailog netDailog;
    private String colleid;//评论id 用于回复
    private String colluserid;//评论者id
    private boolean isReply;//是否为回复状态
    private Requestcollect requestcollect;
    private Requestcancelcollect requestcancelcollect;
    private RequestUserSound requestUserSound;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setContentView(R.layout.activity_videoview);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        mContext = VideoViewActivity.this;
        init();
        initData();
    }

    @Override
    protected void onStart() {
        super.onStart();
        AndroidBug5497Workaround.assistActivity(this);
    }

    private void initData() {
        Intent intent = getIntent();
        mvlistBean = (MvlistBean) intent.getSerializableExtra("mv");
        mvurl = mvlistBean.getSoundurl();
        mvid = mvlistBean.getId();
        playfunction(mvurl);
        myOnClick();
        loadCollListInfo = new LoadCollListInfo();
        loadCollListInfo.execute(mvid);
        title_tv.setText(mvlistBean.getSoundname());
        singer_tv.setText(mvlistBean.getSinger());
        getUserSoundbean();
    }

    private void getUserSoundbean(){
        requestUserSound = new RequestUserSound();
        requestUserSound.execute(mvid);
    }

    private void init() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setPadding(0, CommonUtils.getStatusHeight(VideoViewActivity.this), 0, 0);
        setSupportActionBar(toolbar);
        final ActionBar ab = getSupportActionBar();
        ab.setHomeAsUpIndicator(R.drawable.actionbar_back);
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setTitle("");
        actiobarhei = toolbar.getHeight();
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        showQuickControl(false);
        videoView = (MyVideoView) findViewById(R.id.videoView);
        all_creen = (Button) findViewById(R.id.all_creen);
        video_layout = (RelativeLayout) findViewById(R.id.video_layout);
        all_creen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isScreenOriatationPortrait(mContext)) {// 当屏幕是竖屏时
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);// 设置当前activity为横屏
                    fullscreen = true;
                    // 点击后变横屏
                    RelativeLayout.LayoutParams layoutParams2 =
                            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                    layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                    layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                    layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                    layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                    layoutParams2.addRule(RelativeLayout.CENTER_IN_PARENT);
                    videoView.setLayoutParams(layoutParams2);
                    RelativeLayout.LayoutParams layoutParams1=
                            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
                    video_layout.setLayoutParams(layoutParams1);

//                    if(getActionBar()!=null) {
//                        getActionBar().hide();
//                    }
                    // 当横屏时 把除了视频以外的都隐藏
                    //隐藏其他组件的代码
                } else {
//                    if(getActionBar()!=null) {
//                        getActionBar().show();
//                    }

//                    toolbar.setVisibility(View.VISIBLE);
//                    toolbar.setPadding(0, CommonUtils.getStatusHeight(VideoViewActivity.this), 0, 0);
//                    setSupportActionBar(toolbar);
//                    final ActionBar ab = getSupportActionBar();
//                    ab.setHomeAsUpIndicator(R.drawable.actionbar_back);
//                    ab.setDisplayHomeAsUpEnabled(true);
//                    ab.setTitle("");
                    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, Utils.dip2px(mContext, 200));
                    lp.addRule(RelativeLayout.CENTER_IN_PARENT);
                    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                    lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                    lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                    lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);


                    RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, Utils.dip2px(mContext, 200));
                    lp1.setMargins(0, actiobarhei, 0, 0);

                    video_layout.setLayoutParams(lp1);
                    videoView.setLayoutParams(lp);
                    fullscreen = false;
                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 设置当前activity为竖屏
                    //显示其他组件
                }
            }
        });
        netDailog = new NetDailog(mContext);
        colle_et = (EditText) findViewById(R.id.colle_et);
        send_bt = (Button) findViewById(R.id.send_bt);
        send_bt.setOnClickListener(this);
        video_recyclerviewew = (RecyclerView) findViewById(R.id.video_recyclerviewew);
        manger = new LinearLayoutManager(mContext);
        video_recyclerviewew.setLayoutManager(manger);
        video_recyclerviewew.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL_LIST));
        adapter = new VideoCommentAdapter();
        adapter.setonItemListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                isReply = true;
                colle_et.setHint("回复："+mData.get(position).getSinger());
                colleid = mData.get(position).getId();
                colluserid = mData.get(position).getTageruserid();
            }
        });
        video_recyclerviewew.setAdapter(adapter);

        title_tv = (TextView) findViewById(R.id.title_tv);
        singer_tv = (TextView) findViewById(R.id.singer_tv);
        collection_number_tv = (TextView) findViewById(R.id.collection_number_tv);

        collection_layout = (LinearLayout) findViewById(R.id.collection_layout);
        down_layout = (LinearLayout) findViewById(R.id.down_layout);
        down_layout.setOnClickListener(this);
        share_layout = (LinearLayout) findViewById(R.id.share_layout);
        share_layout.setOnClickListener(this);

        mv_collection_checkbox = (CheckBox) findViewById(R.id.mv_collection_checkbox);
        mv_collection_checkbox.setOnClickListener(this);
    }

    /**收藏请求*/
    class Requestcollect extends AsyncTask<String,Void,Boolean>{

        @Override
        protected Boolean doInBackground(String... params) {
            try{
                JsonObject list = HttpUtil.getResposeJsonObject(User.houseinto(MainApplication.id,MainApplication.sid,"1","3",params[0]));
                String flag = list.get("flag").getAsString();
                if(flag.equals("1")){
                    return true;
                }
                return false;
            }catch(Exception e){
                e.printStackTrace();
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean comlete) {
            if(comlete){
                Toast.makeText(mContext,"收藏成功",Toast.LENGTH_SHORT).show();
                getUserSoundbean();
            }else{
                Toast.makeText(mContext,"收藏失败",Toast.LENGTH_SHORT).show();
                mv_collection_checkbox.setChecked(false);
            }

        }

        public void cancleTask(){
            cancel(true);
            RequestThreadPool.finish();
        }
    }

    /**根据id查询用户声音*/
    class RequestUserSound extends AsyncTask<String,Void,Boolean>{

        @Override
        protected Boolean doInBackground(String... params) {
            try{
                JsonObject object = HttpUtil.getResposeJsonObject(User.getUsersoundbyID(params[0],MainApplication.id,MainApplication.sid));
                String flag = object.get("flag").getAsString();
                userSoundBean = MainApplication.gsonInstance().fromJson(object.getAsJsonObject("data"),UserSoundBean.class);
                if(flag.equals("1")){
                    return true;
                }
            }catch(Exception e){
                e.printStackTrace();
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean comlete) {
            if(comlete){
                if(userSoundBean!=null){
                    if(userSoundBean.getIshouse().equals("y")){
                        mv_collection_checkbox.setChecked(true);
                    }else{
                        mv_collection_checkbox.setChecked(false);
                    }
                }
            }
        }
        public void cancleTask(){
            cancel(true);
            RequestThreadPool.finish();
        }
    }

    /**取消收藏请求*/
    class Requestcancelcollect extends AsyncTask<String,Void,Boolean>{

        @Override
        protected Boolean doInBackground(String... params) {
            try{
                JsonObject list = HttpUtil.getResposeJsonObject(User.houseDel(MainApplication.id,MainApplication.sid,params[0]));
                String flag = list.get("flag").getAsString();
                if(flag.equals("1")){
                    return true;
                }
                return false;
            }catch(Exception e){
                e.printStackTrace();
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean comlete) {
            if(comlete){
                Toast.makeText(mContext,"取消收藏",Toast.LENGTH_SHORT).show();
            }
        }
        public void cancleTask(){
            cancel(true);
            RequestThreadPool.finish();
        }
    }

    @Override
    public void onClick(View view) {
        if(view == send_bt){
            strcoll = colle_et.getText().toString();
            if(strcoll.equals("")){
                Toast.makeText(mContext,"请填写评论",Toast.LENGTH_SHORT).show();
                return;
            }
            if(isReply) {//是否在回复状态
                requestReply = new RequestReply();
//                requestReply.execute(bean.getId());
                requestReply.execute(mvid,colluserid,colleid);
            }else{
                requestSend = new RequestSend();
                requestSend.execute(mvid);
            }
        }else if(view == down_layout){//下载

        }else if(view == share_layout){//分享

        }else if(view == mv_collection_checkbox){//
            if(mv_collection_checkbox.isChecked()){//收藏
                requestcollect = new Requestcollect();
                requestcollect.execute(mvid);
            }else{//取消收藏
                requestcancelcollect = new Requestcancelcollect();
                requestcancelcollect.execute(userSoundBean.getNohouseid());
            }
        }
    }

    /***
     * 回复评论
     * params[0] 音乐id
     * params[1] 评论者的id
     * params[2] 回复数据id
     * */
    class RequestReply extends AsyncTask<String,Void,Boolean> {

        @Override
        protected Boolean doInBackground(String... params) {
            try{
                JsonObject jsonObject = HttpUtil.getResposeJsonObject(HttpUrl.GET_TO_HF,
                        User.getToHf(params[0],"2",strcoll,params[1],MainApplication.id,params[2]));
                String flag = jsonObject.get("flag").getAsString();
                if(flag.equals("1")){
                    return true;
                }
                return false;
            }catch(Exception e){
                e.printStackTrace();
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean comlete) {
            if(comlete){
                isReply = false;
                Toast.makeText(mContext,"回复成功",Toast.LENGTH_SHORT).show();
                loadCollListInfo = new LoadCollListInfo();
                loadCollListInfo.execute(mvid);
                colle_et.setText("");
                colle_et.setHint("");
                MoveToPosition(manger,video_recyclerviewew,0);
                closeInputMethod();
            }else{
                Toast.makeText(mContext,"回复失败",Toast.LENGTH_SHORT).show();
            }
        }

        public void cancleTask(){
            cancel(true);
            RequestThreadPool.finish();
        }
    }

    class RequestSend extends AsyncTask<String,Void,Boolean> {

        @Override
        protected Boolean doInBackground(String... params) {
            try{
                mData.clear();
                JsonObject jsonObject = HttpUtil.getResposeJsonObject(HttpUrl.GET_TO_CT,
                        User.getToCt(params[0],"2",strcoll, MainApplication.id));
                String flag = jsonObject.get("flag").getAsString();
                if(flag.equals("1")){
                    return true;
                }
                return false;
            }catch(Exception e){
                e.printStackTrace();
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean comlete) {
            if(comlete){
                Toast.makeText(mContext,"评论成功",Toast.LENGTH_SHORT).show();
                loadCollListInfo = new LoadCollListInfo();
                loadCollListInfo.execute(mvid+"");
                colle_et.setText("");
                MoveToPosition(manger,video_recyclerviewew,0);
                closeInputMethod();
            }else{
                Toast.makeText(mContext,"评论失败",Toast.LENGTH_SHORT).show();
            }
        }

        public void cancleTask(){
            cancel(true);
            RequestThreadPool.finish();
        }
    }

    private void closeInputMethod(){
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
    /**
     * RecyclerView 移动到当前位置，
     *
     * @param manager   设置RecyclerView对应的manager
     * @param mRecyclerView  当前的RecyclerView
     * @param n  要跳转的位置
     */
    public static void MoveToPosition(LinearLayoutManager manager, RecyclerView mRecyclerView, int n) {


        int firstItem = manager.findFirstVisibleItemPosition();
        int lastItem = manager.findLastVisibleItemPosition();
        if (n <= firstItem) {
            mRecyclerView.scrollToPosition(n);
        } else if (n <= lastItem) {
            int top = mRecyclerView.getChildAt(n - firstItem).getTop();
            mRecyclerView.scrollBy(0, top);
        } else {
            mRecyclerView.scrollToPosition(n);
        }

    }

    class LoadCollListInfo extends AsyncTask<String,Void,Boolean>{

        @Override
        protected Boolean doInBackground(String... params) {
            try{
                mData.clear();
                JsonObject jsonObject = HttpUtil.getResposeJsonObject(User.getCByAlbId(params[0],"2"));
                String flag = jsonObject.get("flag").getAsString();
                JsonArray colllist = jsonObject.get("collList").getAsJsonArray();
                for(JsonElement element : colllist){
                    mData.add(MainApplication.gsonInstance().fromJson(element,CollBean.class));
                }

            }catch(Exception e){
                e.printStackTrace();
            }
            return true;
        }

        @Override
        protected void onPostExecute(Boolean comlete) {
            adapter.setData(mData);
            adapter.notifyDataSetChanged();
        }

        public void cancleTask(){
            cancel(true);
            RequestThreadPool.finish();
        }
    }

    private View crateHeadview() {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View view = inflater.inflate(R.layout.loading_circle, null);
        return view;
    }

    Handler uiHandler = new Handler();

    private void playfunction(String url) {
        if (url.isEmpty()) {
            //TODO
        } else {
            Uri uri = Uri.parse(UrlUtils.toUtf8String(url));
//            videoView.setVideoPath(url);
            videoView.setVideoURI(uri);
            MediaController mc = new MediaController(this);
//            mc.setVisibility(View.GONE);

            videoView.setMediaController(new MediaController(this));
            videoView.requestFocus();
            videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
//                    mediaPlayer.setPlaybackSpeed(1.0f);
                }
            });
        }
    }

    /**
     * 监听
     */
    private void myOnClick() {
        //设置一下监听：播放完成的监听，播放准备好的监听，播放出错的监听

        videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {
                // TODO Auto-generated method stub
                //开始播放
                if(MusicPlayer.isPlaying()){
                    MusicPlayer.stop();
                }
                videoView.start();
                progressDialog2.dismiss();
            }
        });

        videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                Toast.makeText(getApplicationContext(), "视频播放完成了", Toast.LENGTH_SHORT).show();
                finish();//退出播放器
            }
        });

        videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Toast.makeText(getApplicationContext(), "视频播放出错了", Toast.LENGTH_SHORT).show();
                return true;
            }
        });
/**
 * 缓冲设置
 *
 */
        videoView.setOnInfoListener(new MediaPlayer.OnInfoListener() {
            @Override
            public boolean onInfo(MediaPlayer mp, int what, int extra) {
                switch (what) {
                    case MediaPlayer.MEDIA_INFO_BUFFERING_START:
                        if (videoView.isPlaying()) {
                            videoView.pause();

                        }
                        break;
                    case MediaPlayer.MEDIA_INFO_BUFFERING_END:
                        videoView.start();

                        break;
//                    case MediaPlayer.MEDIA_INFO_DOWNLOAD_RATE_CHANGED:
//
//                        break;
                }
                return true;
            }


        });
//        videoView.setBufferSize(1024);

    }

    //  显示界面后，展示dailog
    ProgressDialog progressDialog2 = null;

    @Override
    protected void onResume() {
        super.onResume();
        progressDialog2 = new ProgressDialog(VideoViewActivity.this);
        progressDialog2.setMessage("玩命加载中。。。");
        progressDialog2.setCancelable(true);
        progressDialog2.show();//对话框显示

    }

    /* 返回当前屏幕是否为竖屏。
             *
             * @param context
     * @return 当且仅当当前屏幕为竖屏时返回true,否则返回false。
             */
    public static boolean isScreenOriatationPortrait(Context context) {
        return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    class VideoCommentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
        final static int FIRST_ITEM = 0;
        final static int ITEM = 1;
        private ArrayList<CollBean> mData = new ArrayList<>();
        private OnItemClickListener mOnItemClickListener;

        public void setonItemListener(OnItemClickListener mOnItemClickListener) {
            this.mOnItemClickListener = mOnItemClickListener;
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new VideoCommentAdapter.ListItemViewHolder(LayoutInflater.from(mContext)
                    .inflate(R.layout.item_comment, null));
        }

        @Override
        public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
            if (holder instanceof VideoCommentAdapter.ListItemViewHolder) {
                CollBean bean = mData.get(position);
                ((VideoCommentAdapter.ListItemViewHolder)holder).nametv.setText(bean.getNickname());
                ((VideoCommentAdapter.ListItemViewHolder)holder).datetv.setText(bean.getCrttm());
                if(bean.getUpCollect()!=null) {
                    ((VideoCommentAdapter.ListItemViewHolder) holder).commenttv.setText("回复 "+bean.getUpCollect().getUpsinger()+":"+bean.getNote());
                    ((VideoCommentAdapter.ListItemViewHolder) holder).reply_commenttv.setVisibility(View.VISIBLE);
                    ((VideoCommentAdapter.ListItemViewHolder) holder).reply_commenttv.setText(bean.getUpCollect().getUpsinger()
                            +bean.getUpCollect().getUpnote());
                }else{
                    ((VideoCommentAdapter.ListItemViewHolder) holder).commenttv.setText(bean.getNote());
                    ((VideoCommentAdapter.ListItemViewHolder) holder).reply_commenttv.setVisibility(View.GONE);
                }
                ImageLoader.getInstance().displayImage(bean.getUserimgurl(), ((VideoCommentAdapter.ListItemViewHolder)holder).headiv);
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getLayoutPosition();
                        mOnItemClickListener.onItemClick(v,pos);
                    }
                });
            }
        }

        @Override
        public int getItemViewType(int position) {
            return position ;
        }

        public void setData(ArrayList<CollBean> mData) {
            this.mData = mData;
        }

        @Override
        public int getItemCount() {
            return mData.size();
        }

        class ListItemViewHolder extends RecyclerView.ViewHolder {
            TextView nametv, datetv, praise_num_tv, commenttv, reply_commenttv;
            ImageView headiv, praiseiv;

            public ListItemViewHolder(View view) {
                super(view);
                nametv = (TextView) view.findViewById(R.id.nametv);
                datetv = (TextView) view.findViewById(R.id.datetv);
                praise_num_tv = (TextView) view.findViewById(R.id.praise_num_tv);
                commenttv = (TextView) view.findViewById(R.id.commenttv);
                reply_commenttv = (TextView) view.findViewById(R.id.reply_commenttv);
                headiv = (CircleImageView) view.findViewById(R.id.headiv);
                praiseiv = (ImageView) view.findViewById(R.id.praiseiv);
            }
        }

    }

}
